home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <dos.h>
- #include <conio.h>
- #include <time.h>
-
- #include "lantasti.h"
-
- #define DELIM "+, "
-
- #define LIST_SIZE 50
- #define NAME_SIZE 20
- typedef struct LIST {
- int num_servers,time;
- int available[LIST_SIZE];
- char server[LIST_SIZE][NAME_SIZE];
- } LIST;
-
- /* command line options */
- #define NUM_OPTIONS 2
- char *options[NUM_OPTIONS] = {
- "TIME",
- "HELP"
- };
-
- /***********************************************************************
- Delete leading and trailing blanks.
- ***********************************************************************/
- void dltb(string)
- char *string;
- {
- register int i;
-
- i = strspn(string," ");
- if (i) strcpy(string,string + i);
-
- i = strlen(string) - 1;
- while (i && (string[i] == ' ')) {
- string[i--] = '\0';
- }
- }
- /* get_active_servers ********************************************************************
- Gets a list of the active servers.
- *****************************************************************************/
- void get_active_servers(list)
- LIST *list;
- {
- char buffer[17];
- int index,result;
-
- index = 0;
- /* pull in the name of a server */
- while ((result = get_active_server(buffer,index++))) {
- sprintf(list->server[list->num_servers++],"\\\\%s",buffer);
- /* only allow a reasonable number of servers */
- if (list->num_servers >= LIST_SIZE) {
- puts("Warning: Too many servers. Only the first 50 can be used.");
- break;
- }
- }
- }
-
- /* get_available_servers ********************************************************************
-
- *****************************************************************************/
- void get_available_servers(list)
- LIST *list;
- {
- char buffer[17];
- int index,result;
-
- index = 0;
- result = get_active_server(buffer,index);
- while (result) {
- dltb(buffer);
- strcpy(list->server[list->num_servers++],buffer);
- if (list->num_servers >= LIST_SIZE) {
- puts("Warning: Too many servers. Only the first 50 can be used.");
- break;
- }
- result = get_active_server(buffer,++index);
- }
-
- result = get_inactive_server(buffer,index);
- while (result) {
- dltb(buffer);
- strcpy(list->server[list->num_servers++],buffer);
- if (list->num_servers >= LIST_SIZE) {
- puts("Warning: Too many servers. Only the first 50 can be used.");
- break;
- }
- result = get_inactive_server(buffer,++index);
- }
- }
-
- /* process_server_list ********************************************************************
-
- *****************************************************************************/
- void process_server_list(string,list)
- char *string;
- LIST *list;
- {
- char *ptr;
-
- ptr = strtok(string,DELIM);
-
- while (ptr !=NULL) {
- list->available[list->num_servers] = FALSE;
- strcpy(list->server[list->num_servers++],ptr);
-
- if (list->num_servers >= LIST_SIZE ) {
- puts("Warning: Too many servers. Only the first 50 will be used.");
- break;
- }
- ptr = strtok(NULL," ,");
- }
- }
-
- /* process_option ********************************************************************
-
- *****************************************************************************/
- void process_option(string,list)
- char *string;
- LIST *list;
- {
- char *ptr;
- int i,tm;
-
- ptr = strtok(string,"=:");
-
- for (i = 0; i < NUM_OPTIONS; i++) {
- if (!strcmpi(ptr,options[i])) break;
- }
-
- if (i >= NUM_OPTIONS) {
- printf("Whoops! %s isn't a valid command line option.\n",ptr);
- return;
- }
-
- ptr = strtok(NULL," =");
-
- switch (i) {
- case 0: /* time */
- tm = atoi(ptr);
- if ((tm >= 0) && (tm <= 999)) list->time = tm;
- else {
- printf("Whoops! %d isn't a valid timeout value (0..999 seconds).\n",tm);
- puts("Assuming default value (no timeout)");
- list->time = 0;
- }
- break;
- case 1: /* help */
- puts("WAITFOR utility for LANtastic -- Copyright 1989 by SoftMagic, Inc.");
- puts("All rights reserved. LANtastic is a trademark of Artisoft, Inc.\n");
- puts("Usage: WAITFOR <server list> [/OPTIONS]");
- puts("Pauses until all the given servers are on line or until the");
- puts("user presses escape or the optional timeout expires.\n");
- puts("Available options are:");
- puts("/TIME - specify timeout value in seconds");
- puts("/HELP - display this documentation");
- exit(0);
- break;
- }
- }
-
- /* scan_command_line ********************************************************************
-
- *****************************************************************************/
- scan_command_line(argc,argv,list)
- int argc;
- char *argv[];
- LIST *list;
- {
- int i,state;
- char s_buffer[128];
-
- list->num_servers = 0;
-
- for (i = 1;i < argc; i++) {
- strupr(argv[i]);
- if (argv[i][0] == '/') {
- process_option(&argv[i][1],list);
- continue;
- }
- else process_server_list(argv[i],list);
- }
- }
-
- /* waitfor ********************************************************************
-
- *****************************************************************************/
- int waitfor(list)
- LIST *list;
- {
- LIST avail;
- int i,j,result;
- unsigned long st_time,curr_time;
-
- result = FALSE;
-
- time(&st_time);
- curr_time = st_time;
-
- /* while not all servers are available */
- while (!result) {
- time(&curr_time);
- if (list->time < (curr_time - st_time)) break;
-
- if (kbhit()) if (getch() == 27) break;
-
- result = TRUE;
-
- avail.num_servers = 0;
- get_available_servers(&avail);
-
- for (i = 0;i < list->num_servers; i++) {
- for (j = 0; j < avail.num_servers; j++) {
- if (!strcmp(list->server[i],avail.server[j]))
- list->available[i] = TRUE;
- }
- result = result && list->available[i];
- }
- time(&curr_time);
- if (list->time < (curr_time - st_time)) break;
- }
- return(!result); /* return 0 if ok, 1 if error */
- }
-
- /* main ********************************************************************
-
- *****************************************************************************/
- int main(argc,argv)
- int argc;
- char *argv[];
- {
- LIST list;
-
- list.time = 32767; /* default wait time */
-
- #ifdef SHAREWARE
- puts("WAITFOR utility for LANtastic -- Copyright 1989 by SoftMagic, Inc.");
- puts("All rights reserved. Thanks for trying this unregistered Shareware edition!\n");
- #endif
-
- scan_command_line(argc,argv,&list);
-
- return(waitfor(&list));
- }